const { Client } = require('pg');
require('dotenv').config({ path: '../backend/.env' });

// Database configuration
const dbConfig = {
  host: process.env.DB_HOST || 'localhost',
  port: process.env.DB_PORT || 5432,
  database: process.env.DB_NAME || 'financeapp',
  user: process.env.DB_USER || 'beauty_admin',
  password: process.env.DB_PASSWORD || 'Beauty5alon2025SecureKey',
};

async function verifyIndexes() {
  const client = new Client(dbConfig);
  
  try {
    // Connect to database
    await client.connect();
    console.log('Database connected successfully');
    
    // Query to check indexes
    const query = `
      SELECT 
        tablename,
        indexname,
        indexdef
      FROM pg_indexes 
      WHERE schemaname = 'public'
      ORDER BY tablename, indexname;
    `;
    
    const result = await client.query(query);
    
    console.log('\nDatabase Indexes:');
    console.log('==================');
    
    let currentTable = '';
    result.rows.forEach(row => {
      if (row.tablename !== currentTable) {
        currentTable = row.tablename;
        console.log(`\nTable: ${currentTable}`);
      }
      console.log(`  - ${row.indexname}`);
    });
    
    console.log('\nIndex verification completed successfully');
  } catch (error) {
    console.error('Error verifying indexes:', error);
  } finally {
    await client.end();
  }
}

// Run verification
verifyIndexes();